csv-async
This is CSV library to use in asynchronous environment.
Implemented API is similar to existing csv crate with few exceptions like builder's create_
functions instead of from_
as in csv
.
Some code is borrowed from csv
crate (synchronized with version 1.3.3 - Oct 2023).
This package shares CSV parsing routines with csv
by means of using csv-core
crate.
Major version of this crate will be kept in sync with major version of csv
with which it is API compatible.
CSV files are being read or written by objects of types AsyncReader
/ AsyncWriter
to / from generic
text-based structures or by AsyncDeserializer
/ AsyncSerializer
to / from data specific structures with generated serde
interfaces.
Library does not contain synchronous reader/writer. If you need it - please use csv
crate.
Cargo Features
Features which can be enabled / disabled during library build.
Feature | Default | Description |
---|---|---|
with_serde |
on | Enables crate to use serde derive macros |
tokio |
off | Enables crate to be used with tokio runtime and libraries |
Enabling tokio
feature allows user to use tokio::fs::File
and makes AsyncReader
(AsyncWriter
)
to be based on tokio::io::AsyncRead
(tokio::io::AsyncWrite
). Currently this crate depends on tokio version 1.25.
Without tokio
feature, this crate depends only on futures
crate and reader (writer) are based on traits futures::io::AsyncRead
(futures::io::AsyncWrite
), what allows user to use async_std::fs::File
.
Example usage:
Sample input file:
city,region,country,population
Southborough,MA,United States,9686
Northbridge,MA,United States,14061
Marlborough,MA,United States,38334
Springfield,MA,United States,152227
Springfield,MO,United States,150443
Springfield,NJ,United States,14976
Concord,NH,United States,42605
use Error;
use process;
use StreamExt;
use File;
async
For serde example please see documentation root page.
Plans
Some ideas for future development:
- Create benchmarks, maybe some performance improvements.
- Things marked as TODO in the code.
- Support for
smol
asynchronous runtime. - Create more examples and tutorial.